package com.knowledge.controller;

import com.knowledge.common.aop.TokenValidate;
import com.knowledge.service.SysUserService;
import com.knowledge.vo.Result;
import com.knowledge.vo.params.ChangePwdParam;
import com.knowledge.vo.params.SetAdminParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zzz
 * @create 2022-02-11 15:32
 */
@RestController
@RequestMapping("users")
public class UserController {
    @Autowired
    private SysUserService sysUserService;

    @TokenValidate
    @GetMapping("currentUser")
    public Result currentUser(@RequestHeader("Authorization") String token){

        return sysUserService.findUserByToken(token);
    }

    @TokenValidate
    @PostMapping("changePwd")
    public Result changePassword(@RequestBody ChangePwdParam changePwdParam) {
        return sysUserService.changePassword(changePwdParam);
    }

    @TokenValidate
    @PostMapping("admin")
    public Result setAdmin(@RequestBody SetAdminParam param) {
        return sysUserService.setAdmin(param);
    }
}
